package com.qqclient.view;
//打印菜单
import com.qqclient.Utils.Utility;
import com.qqclient.service.FileClientService;
import com.qqclient.service.MessageClinetService;
import com.qqclient.service.UserClinentService;

import java.io.IOException;

public class QQview {
    private Boolean loop=true;
    private String key;
    private UserClinentService userClinentService=new UserClinentService();
    private MessageClinetService messageClinetService=new MessageClinetService();//用于消息的发送
    private FileClientService fileClientService=new FileClientService();//用于接收文件

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        QQview qqview = new QQview();
        qqview.mainMenu();
    }
    private void mainMenu() throws IOException, ClassNotFoundException {
        while(loop){
            System.out.println("==========欢迎登录山寨版QQ==========");
            System.out.println("\t\t 1 登录系统");
            System.out.println("\t\t 9 退出系统");
            System.out.print("请输入你的选择：");
            key = Utility.readString(1);
            switch(key){
                case "1":
                    System.out.print("请输入用户号：");
                    String userId = Utility.readString(50);
                    System.out.print("请输入密  码：");
                    String pwd = Utility.readString(50);
                    if (userClinentService.checkUser(userId,pwd)){
                        System.out.println("=======欢迎("+userId+")=======");
                        while (loop){
                            System.out.println("\n=======山寨版QQ二级菜单=======");
                            System.out.println("\t\t 1 显示在线用户列表");
                            System.out.println("\t\t 2 群发消息");
                            System.out.println("\t\t 3 私发消息");
                            System.out.println("\t\t 4 发送文件");
                            System.out.println("\t\t 9 退出系统");
                            System.out.print("请输入你的选择：");
                             key = Utility.readString(1);
                             switch(key){
                                 case "1":
                                     userClinentService.onlineFriendList();
                                     break;
                                 case "2":
                                     System.out.print("请输入想对大家说的话：");
                                     String content = Utility.readString(1000);
                                     messageClinetService.sendMessageAll(content,userId);
                                     break;
                                 case "3":
                                     System.out.print("请输入私聊用户名(在线)：");
                                     String getterId = Utility.readString(50);
                                     System.out.print("请输入说话内容：");
                                     String content1 = Utility.readString(1000);
                                     messageClinetService.sendMessageToOne(content1,userId,getterId);
                                     break;
                                 case "4":
                                     System.out.print("请输入把文件发送的用户：");
                                     getterId = Utility.readString(1000);
                                     System.out.println("请输入发送文件的路径:(以 d:\\xx.jpg)");
                                     String src = Utility.readString(1000);
                                     System.out.println("请输入接收文件的路径:(以 d:\\MM.jpg)");
                                     String dest = Utility.readString(1000);
                                     fileClientService.sendFileToOne(src,dest,userId,getterId);
                                     break;
                                 case "9":
                                     userClinentService.logcut();
                                     loop=false;
                                     break;

                             }
                        }
                    }else {
                        System.out.println("登录失败");
                    }
                    break;
                case "9":
                    loop=false;
                    break;
            }

        }
        System.out.println("退出山寨版QQ");
    }
}
